#/bin/python
#coding:utf8
'''
Created on 2011-5-2

@author: mark
'''

import web
import os
from util import json
import config
from util import basic

tp = config.template_test

class userlogoUpload:
    '''
        the user upload for the personal logo
    '''
    def POST(self):
        i = web.input(xmfile={})        
        
        current_user = web.ctx.session['current_user']
        uid = int(current_user['uid'])
        
        if 'xmfile' in i:
            filepath = os.path.join(config.upload_path, basic.uphotoname(i['xmfile'].filename, uid))
            showpath = "static/upload/"+basic.uphotoname(i['xmfile'].filename, uid)
            try:
                fout = open(filepath, 'wb')
                fout.write(i.xmfile.file.read())
                fout.close()
            except Exception:
                return json.write({"error":0, "msg":"Upload Error"})
        #return json.write({"error":str(1), "msg":showpath})
        return showpath
    
    def GET(self):
        return tp.upload()
    
class picutreUpload:
    def POST(self):
        pass
